/**
Singleton Holder Template

 Written in the D programming language 1.0

Authors:
	Wei Li (oldrev@gmail.com)

License:
	BSD

Copyright:
	Copyright (C) 2007 The DotMars Team. 
*/

module dotmars.base.singletion;


/**
  * SingletonHolder is a implemention of singleton pattern
  */
final static class SingletonHolder(T)
{
	public alias SingletonHolder!(T) SelfType;
   	private static T m_instance;

   	private synchronized static this()
   	{
        static assert(is(T == class) || is(T == struct) || is(T == union), 
                "SingletonHolder: struct, union and class only");

		static if(is(T == class))
   			m_instance = new T();
	}

    public static T instance()
    {
		static if(is(T == class))
            assert(m_instance !is null);
           
        return m_instance;
    }

    public static T opCall()
    {
        return instance;
    }
}

